package b2.widget
{
	import b2.net.*;
	import b2.util.*;
	
	import com.bit101.components.*;
	
	import flash.display.*;
	import flash.events.*;

	public class DebugPane extends Sprite
	{
		private var list:List;
		private static var instance:DebugPane;
		private static const BUF_SIZE:int = 500;
		private var bgr:Sprite;
		private var lastText:String;
		//调试flix 帧率
		public var flixfr:FrameRater;

		public function DebugPane()
		{
			super();
			bgr = new Sprite();
			var gfx:Graphics = bgr.graphics;
			gfx.lineStyle(2, 0x27AAE1);
			gfx.moveTo(0, 0);
			gfx.beginFill(0x27AAE1);
			gfx.lineTo(BFont.stageWidth, 0);
			gfx.lineTo(BFont.stageWidth, BFont.stageHeight);
			gfx.lineTo(0, BFont.stageHeight);
			gfx.lineTo(0, 0);
			gfx.endFill();
			addChild(bgr);
			Style.embedFonts = false;
			Style.fontName = "微软雅黑";
			Style.fontSize = 16;
			list = new List(this, 20, 20);
			list.setSize(750, 550);
			list.listItemHeight = 20;
			list.autoHideScrollBar = true;
			var fr:FrameRater = new FrameRater(0xffffff, true, false);
			// position it where you want
			fr.x = 647;
			fr.y = 547 - 10;
			// add it to the displayList
			addChild(fr);
			
			flixfr = new FrameRater(0xffffff, true, false);
			flixfr.isFlix = true;
			flixfr.x = 647;
			flixfr.y = 547 + 17;
			// add it to the displayList
			addChild(flixfr);

			this.addEventListener(MouseEvent.CLICK, onMouseClick);
		}
		
		public static function getInstance():DebugPane
		{
			if (!instance)
				instance = new DebugPane();
			return instance;
		}
		
		private function onMouseClick(event:MouseEvent):void
		{
			bgr.visible = !bgr.visible;
			list.visible = !list.visible;
		}	
		
		public function close():void
		{
			if (this.parent != null)
				this.parent.removeChild(this);
		}
		
		public function addInfo(text:String):void
		{
			if (lastText != text)
			{
				if (list.items.length > BUF_SIZE)
					list.removeAll();
				list.addItemAt(text, 0);
				lastText = text;
			}
		}
		
	}
}